var log = document.getElementsByClassName('log')[0]
var reg = document.getElementsByClassName('reg')[0]
var hellouser = document.getElementsByClassName('hellouser')[0]
var goodsList = document.getElementsByClassName('goods-list')[0]
var banner = document.getElementsByClassName('banner')[0]

var lgc = getCookie('lgc')
if (lgc) {
    log.innerHTML = lgc
    reg.innerHTML = '退出登录'
    hellouser.innerHTML = lgc
    reg.onclick = function () {
        delCookie('lgc')
        log.innerHTML = `<a href="./login.html">请登录</a>`
        reg.innerHTML = `<a href="./register.html">注册有礼</a>`
        hellouser.innerHTML = ` 登录 | 注册 `
    }
}


searchAllGoods().then(res => {
    var { list } = res
    var html = ``
    list.forEach(item => {
        var { id, goodsId, goodsName, goodsImg, goodsPrice } = item
        html += `
                    <li> <a href="./details.html?goodInfo=${goodsId}">
                    <img src="${goodsImg}"
                        alt="">
                    <div class="price">￥${(parseInt(goodsPrice).toFixed(2))}</div>
                    <div class="desc">${goodsName}</div>
                    </a></li>
                    `
    })
    goodsList.innerHTML = html
})

var searchBtn = document.getElementsByClassName('btn')[0]
var searchInfo = document.getElementsByClassName('search-inp')[0]

searchBtn.onclick = function () {
    var searchVal = searchInfo.value
    location.href = './search.html?goodInfo=' + searchVal
}
